package com.hgt.springcloud.controller;

import com.hgt.springcloud.service.OrderHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: huanggaotao
 * @Description:
 * @Date: Created in 11:49 2021/6/22
 * @Modified By:
 */
@RestController
@Slf4j
//如果自己设置了特定的，没有设置就通用这个
//@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class OrderHystrixController {

    @Autowired
    OrderHystrixService orderHystrixService;

    @GetMapping("/consumer/hystrix/ok/{id}")
    public String paymentInfo_ok(@PathVariable("id") Integer id ){
        return orderHystrixService.paymentInfo_OK(id);
    }

    @GetMapping("/consumer/hystrix/timeout/{id}")
//    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutMethod",commandProperties = {
//            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "1500")
//    })
    public String paymentInfo_timeout(@PathVariable("id") Integer id ){
        int age = 10/0;
        return orderHystrixService.paymentInfo_TimeOut(id);
    }

    //服务降级所使用的方法
    public String paymentInfo_TimeOutMethod(@PathVariable("id") Integer id){
        return "我是消费者80，对方支付系统繁忙请10秒钟后再试或者自己运行出错请检查自己******";
    }

    //下面是全局 fallback方法
    public String payment_Global_FallbackMethod(){
        return "Global异常处理信息，请稍后再试，/(T o T)/~~";
    }
}
